"""
python常用的内建方法
"""
from utils.test_tools import test_decorator


# 1、abs()
@test_decorator('test build in function: abs()')
def test_abs():
    # return the absolute value of a number. the argument may be an integer
    # or a float point number.
    integer = -1
    abs_integer = abs(integer)
    print(abs_integer)
    float_ = -2.1
    abs_float_ = abs(float_)
    print(abs_float_)


@test_decorator('test build in function: all()')
def test_all():
    """
    build in function all equal to this all function:
    def all(iterable):
        for item in iterable:
            if not item:
                return False
        return True
    """
    ls = [1, 2, 3, 4, 5]
    res = all(ls)
    print(res)
    ls.append(0)
    res = all(ls)
    print(res)


@test_decorator('test build in function: any()')
def test_any():
    """
    build in function and equal to this any function:
    def any(iterable):
        for item in iterable:
            if item:
                return True
        return False
    """
    ls = [1, 2, 3, 4, 5]
    res = any(ls)
    print(res)
    ls_n = [None, None, 0]
    res = any(ls_n)
    print(res)
    ls_n.append(1)
    res = any(ls_n)
    print(res)


@test_decorator('test build in function: bin()')
def test_bin():
    """
    convert an integer number to binary string prefixed with '0b'
    """
    integer = 3
    bin_integer = bin(integer)
    print(bin_integer)


@test_decorator('test build in function: divmod')
def test_divmod():
    """
    take two numbers as arguments and return a pair of numbers
    consisting of their quotient and remainder when using integer.
    equal to this:
        divmod(a, b) ==> (a//b, a%b)
    """
    a = 10
    b = 3
    quotient, remainder = divmod(a, b)
    print(quotient, remainder)
    print(a // b, a % b)


if __name__ == '__main__':
    test_abs()
    test_all()
    test_any()
    test_bin()
    test_divmod()
    test_divmod
